package com.itheima.motorcycletype.controller;

import com.carkeeper.entity.PageResult;
import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.github.pagehelper.Page;

import com.itheima.motorcycletype.pojo.MotorcycleType;
import com.itheima.motorcycletype.service.MotorcycleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/motorcycletype")
public class MotorcycleTypeController {
    @Autowired
    private MotorcycleTypeService motorcycleTypeService;
    /**
     * 分页查询
     * @param map
     * @return
     */
    @GetMapping
    public Result selectAll(@RequestParam Map map){
        Page<MotorcycleType> MotorcycleTypePage = motorcycleTypeService.selectAll(map);
        PageResult pageResult = new PageResult(MotorcycleTypePage.getTotal(), MotorcycleTypePage.getResult());
        return new Result(true, StatusCode.OK,"查询成功",pageResult);
    }

    /**
     * 添加车标
     * @param motorcycleType
     * @return
     */
    @PostMapping
    public Result add(@RequestBody MotorcycleType motorcycleType){
        Integer add = motorcycleTypeService.add(motorcycleType);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /**
     * 修改车标
     * @param motorcycleType
     * @return
     */
    @PutMapping
    public Result update(@RequestBody MotorcycleType motorcycleType){
        Integer update = motorcycleTypeService.update(motorcycleType);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /**
     * 删除车标
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id){
        Integer delete = motorcycleTypeService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }
}
